var app = getApp();
var req = require("../../utils/req.js");
var url = require("../../utils/url.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mobile: '',
    userId: '',
    money: ''
  },
  mobileInput: function(e) {
    this.setData({
      mobile: e.detail.value
    })
  },
  userIdInput: function(e) {
    this.setData({
      userId: e.detail.value
    })
  },
  priceInput: function(e) {

    var money;
    if (/^(\d?)+(\.\d{0,2})?$/.test(e.detail.value)) { //正则验证，提现金额小数点后不能大于两位数字
      money = e.detail.value;
    } else {
      money = e.detail.value.substring(0, e.detail.value.length - 1);
    }
    this.setData({
      money: money,
    })
  },
  onUnload:function(){
    this.setData({
      mobile:'',
      userId:'',
      money:''
    })
  },
  // 确认充值
  helpRecharge: function() {
    if (this.data.userId == '') {
      wx.showToast({
        icon: 'none',
        title: '请输入正确用户ID',
      })
      return;
    } else if (this.data.mobile == '') {
      wx.showToast({
        icon: 'none',
        title: '请输入正确手机号码',
      })
      return;
    } else if (this.data.money == '' || this.data.money == 0){
      wx.showToast({
        icon: 'none',
        title: '请输入正确金额',
      })
      return;
    } else if (this.data.money==10000){
      wx.showToast({
        icon: 'none',
        title: '金额不能超过10000',
      })
      return;
    }
    var storeId = app.globalData.storeId;
    var data = {
      userId: this.data.userId,
      phone: this.data.mobile,
      money: this.data.money
    }
    wx.showModal({
      title: '提示',
      content: '是否确认充值',
      success(res){
         if(res.confirm){
           req.storeRequest("请稍等", 'POST',url.store['storeRechargesToUser'], storeId, data, function back(res) {
             app.globalData.isNewUserInfo = true;
             wx.showToast({
               title: res.msg,
               duration: 1500,
               success: function () {
                 setTimeout(function () {
                   wx.redirectTo({
                     url: '/pages/storeStatus/storeStatus?helpRecharge=' + true,
                   })
                 }, 1500);
               }
             })
           })
         }
      }
    })
  }
})